package everyday;

import java.util.*;

/**
 * @Author: Siantar
 * @Date: 2023-06-06-21:37
 * @Description: 1.0
 */
public class T2352 {
    public int equalPairs(int[][] grid) {
        int n = grid.length;
        Map<List<Integer>, Integer> map = new HashMap();
        for (int i = 0; i < n; i++) {
            List<Integer> list = new ArrayList<>();
            for (int j = 0; j < n; j++) {
                list.add(grid[i][j]);
            }
            map.put(list, map.getOrDefault(list, 0) + 1);
        }
        int sum = 0;
        for (int i = 0; i < n; i++) {
            List<Integer> list = new ArrayList<>();
            for (int j = 0; j < n; j++) {
                list.add(grid[j][i]);
            }
            sum += map.getOrDefault(list,0);
        }
        return sum;
    }
}
